package com.rhino.security.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.rhino.security.constants.SecurityConstants;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @ClassName RestResult
 * @Description Rest接口统一返回结果，前端统一解析
 * @Author zyk
 * @Create 2021/7/12
 * @Version 1.0
 **/
@Data
@ApiModel("REST API 响应结果说明")
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public class RestResult {
    @ApiModelProperty("响应状态：20000，50000")
    public int status;

    @ApiModelProperty("响应信息说明")
    public String msg;

    @ApiModelProperty("接口响应内容")
    @JsonInclude(value = JsonInclude.Include.ALWAYS)
    public Object data;

    RestResult(int type, String message,Object data){
        this.status=type;
        this.msg=message;
        this.data=data;
    }

    @Override
    public String toString() {
        return "JsonResult{" +
                "status=" + status +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public static RestResult FAIL(String msg, Object data){
        return new RestResult(SecurityConstants.FAIL,msg,data);
    }
    public static RestResult FAIL(String msg){
        return new RestResult(SecurityConstants.FAIL,msg,null);
    }

    public static RestResult OK(String msg){
        return new RestResult(SecurityConstants.OK,msg,null);
    }
    public static RestResult OK(String msg,Object data){
        return new RestResult(SecurityConstants.OK,msg,data);
    }
    public static RestResult OK(Object data){
        return new RestResult(SecurityConstants.OK,"",data);
    }

    public static RestResult UNAUTH(String msg){
        return new RestResult(SecurityConstants.UNAUTHORITED,msg,null);
    }
    public static RestResult UNAUTH(String msg,Object data){
        return new RestResult(SecurityConstants.UNAUTHORITED,msg,data);
    }

}
